package cn.qg.biz.service.qguser;
import cn.qg.beans.pojo.QgUser;
import cn.qg.common.Constants;
import cn.qg.common.EmptyUtils;
import cn.qg.common.Page;
import cn.qg.mapper.qguser.QgUserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class QgUserServiceImpl implements QgUserService {

    @Resource
    private QgUserMapper qgUserMapper;

    @Override
    public QgUser getQgUserById(Long id)throws Exception{
        return qgUserMapper.getQgUserById(id);
    }

    @Override
    public List<QgUser>	getQgUserListByMap(Map<String,Object> param)throws Exception{
        return qgUserMapper.getQgUserListByMap(param);
    }

    @Override
    public Integer getQgUserCountByMap(Map<String,Object> param)throws Exception{
        return qgUserMapper.getQgUserCountByMap(param);
    }

    @Override
    public Integer qgtxAddQgUser(QgUser qgUser)throws Exception{
            qgUser.setCreatedTime(new Date());
            return qgUserMapper.insertQgUser(qgUser);
    }

    @Override
    public Integer qgtxModifyQgUser(QgUser qgUser)throws Exception{
        qgUser.setCreatedTime(new Date());
        return qgUserMapper.updateQgUser(qgUser);
    }

    @Override
    public Integer qgtxDeleteQgUserById(Long id)throws Exception{
        return qgUserMapper.deleteQgUserById(id);
    }

    @Override
    public Page<QgUser> queryQgUserPageByMap(Map<String,Object> param,Integer pageNo,Integer pageSize)throws Exception{
        Integer total = qgUserMapper.getQgUserCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<QgUser> qgUserList = qgUserMapper.getQgUserListByMap(param);
        page.setRows(qgUserList);
        return page;
    }

}
